package com.bootdo.imgtext.check.impl;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.bootdo.imgtext.check.CheckService;

public class PeopleImpl extends CheckService {

	public PeopleImpl(String url) {
		Document doc = getDoc(url);

		Element content = null;
		if (doc != null) {
			content = doc.select("div#rwb_zw").first();
		} else {
			return;
		}

		// 作者有可能会出现在最后的大字里，也有可能出现在最后一段的最后的括号里
		// Element authorEle = content.select("p").last();
		// String authorName = authorEle.select("strong").text().trim();
		// if (authorName.contains("作者")) {
		// author = authorName;
		// } else {
		// // 判断倒数第二个<p>中最后的括号， jsoup不支持css3 nth-last-child选择器
		// Elements paragraphs = content.select("p");
		// if (paragraphs.size() > 1) {
		// String lastParagraph = paragraphs.get(paragraphs.size() - 2).text().trim();
		// if (lastParagraph.length() > 4 && lastParagraph.lastIndexOf('）') ==
		// lastParagraph.length() - 1) {
		// author = lastParagraph.substring(lastParagraph.lastIndexOf('（') + 1,
		// lastParagraph.length() - 1);
		// }
		// }
		//
		// }

		Element first = doc.select("div.box01").select("div.fl").first();
		if (first != null) {
			// 使用来源代替作者
			String header = first.text().trim();
			if (header.contains("来源")) {
				author = header.substring(header.indexOf("来源"));
			}
		}

		if (content == null) {
			return;
		}
		Elements imgs = content.select("img[src]");
		checkImgs(imgs);
	}
}
